package javao.cn.work.orc.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2WebMvc;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Configuration
@EnableSwagger2WebMvc
public class Knife4jConfiguration {


    @Autowired
    private MyConfig myConfig;


    @Bean(value = "defaultApi2")
    public Docket defaultApi2() {
        String groupName="ORC测量报告内容识别系统";
        Docket docket= null;
        try {
            docket = new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(new ApiInfoBuilder()
                            .title("VWED_ORC_PDF_API")
                            .description("\n\n\n" +
                                    "\n\n\n"
                                    +"在线日志监控：http://"+ InetAddress.getLocalHost().getHostAddress()+":"+myConfig.getPort()+ "/logging.html" +
                                    "\n\n\n"
                            )
                            .termsOfServiceUrl("http://www.vwed.com/")
                            .contact("programmer3.cc.vwed.com")
                            .version("1.0")
                            .build())
                    //分组名称
                    .groupName(groupName)
                    .select()
                    //这里指定Controller扫描包路径
                    .apis(RequestHandlerSelectors.basePackage("javao.cn.work.orc.controller"))
                    .paths(PathSelectors.any())
                    .build();
        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        }
        return docket;
    }

}
